home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / mgabra.zip / MGABRA.ASM < prev    next >
Assembly Source File  |  1988-12-01  |  39KB  |  1,177 lines

  1. PAGE    55,132
  2. TITLE   ABRACADABRA! MAGIC SOFTWARE TSR/TCR (Terminate Cont Running) LIBRARY
  3.  
  4. INCLUDE MGMMACS.ASM
  5.  
  6. DEINT   EQU     0e0h            ;Deinstall Interrupt
  7.  
  8. STKSAV  EQU     32
  9.  
  10. INCLUDE MGLANGC.ASM
  11.  
  12. ;------------------------------------------------
  13. ; SEGMENT DEFINITIONS
  14. ;------------------------------------------------
  15.  
  16.     EXTRN __psp:WORD
  17.  
  18. _BSS    SEGMENT WORD PUBLIC 'BSS'
  19. _BSS    ENDS
  20.  
  21. DGROUP  GROUP   _DATA, _BSS
  22. _DATA   SEGMENT WORD PUBLIC 'DATA'
  23.         ASSUME  DS:DGROUP, SS:DGROUP
  24. _DATA   ENDS
  25.  
  26. _TEXT   SEGMENT BYTE PUBLIC 'CODE'
  27.         ASSUME  CS:_TEXT
  28.  
  29.      EXTRN _tsrexit:FAR
  30.  
  31. ;------------------------------------------------
  32. ; PUBLICS - Functions you can call
  33. ;------------------------------------------------
  34.  
  35.         PUBLIC  _swpscr
  36.         PUBLIC  _hotkey
  37.         PUBLIC  _timer
  38.         PUBLIC  _swap
  39.         PUBLIC  _tsrset
  40.         PUBLIC  _swping
  41.         PUBLIC  _swapno
  42.     PUBLIC  _swapyes
  43.         PUBLIC  _status
  44.         PUBLIC  _id
  45.         PUBLIC  _putchr
  46.         PUBLIC  _conout
  47.         PUBLIC  _inkey
  48.     PUBLIC  _bykey
  49.  
  50. ;-----------------------------------------------------
  51. ; TCB (Task Control Blocks)
  52. ; Areas where various info about the processs are kept
  53. ;-----------------------------------------------------
  54.  
  55. dosprg   dw      60 dup (0)             ;TCB for TSR program
  56. tsrprg   dw      60 dup (0)             ;TCB for Interrupted program
  57.  
  58. dosprgs  db      4000 dup (0)           ;area for saving TSR's screen
  59. tsrprgs  db      4000 dup (0)           ;area for saving interrupted's screen
  60.  
  61. swptog  dw      0                       ;swapping disabled? 1 = yes
  62. scrswp  dw      0                       ;screen swap mode
  63. timed   dw      0                       ;time triggering on? 1 = yes
  64. by28    dw      0                       ;invoked within int28 call?
  65. keyswap dw      0                       ;was swapping done on key control?
  66. keypop    dw    0            ;last swap by key? (retained)
  67. period  dw      0                       ;how many 1/18sec do we run for?
  68. doswap  dw      0                       ;"I want to swap" flag
  69. inproc  dw      0                       ;busy swapping processes flag
  70. hard_bz dw      0                       ;hardware busy flag
  71. flag_28 dw      0                       ;interrupt 28 live
  72. prob28h dw      0                       ;is int28 a problem? 0 = yes
  73. videosz dw      0                       ;size of video screen
  74. videos  dw      0                       ;dynamic base of video seg
  75. videom  dw      0                       ;current video mode
  76. videop  dw      0                       ;current video page
  77. procid  dw      0                       ;this programs id number
  78. stflag  dw      0                       ;polled status
  79. errflag dw      0                       ;critical error number
  80. envadd  dw      0                       ;paragraph of environment
  81. entry   dw      0                       ;IP of TSR upon initialization
  82. indoss  dw      0                       ;dos busy flag segment
  83. indoso  dw      0                       ;dos busy flag offset
  84. init    dw      0                       ;TSR initialized?
  85. savpar  dw      0                       ;paragraphs to save
  86. add6845 dw      0                       ;address of 6845 video controller
  87. color   dw      0b800h                  ;base of color video area
  88. mono    dw      0b000h                  ;base of monochrome video area
  89. hotkey  db      0                       ;hotkey scan code
  90. hotstat db      0                       ;hot key shift key
  91. err0    db    'ABRACADABRA ERROR: $'
  92. err1    db    'Not Enough Memory$'
  93. err2    db    'Illegal Use of DOS Function Below 0CH$'
  94. err3    db    'Insufficient Memory - Language Does Not Return Excess to Dos$'
  95. err4    db    'Synchronization$'
  96. hithere db    'Source Code Is Available Dude! Walt Howard 213-477-4151'
  97. coprght db      'Copyright (c) 1988 by Walter F. Howard Jr.'
  98. vrsn    db    '1.2 For TURBO C ONLY!'
  99.  
  100. ;-------------------------------------------------------
  101. ; DOS interrupt values
  102. ; Here is where the old interrupt vectors are kept saved
  103. ;-------------------------------------------------------
  104.  
  105. disk_int label  dword                   ;int 13h (disk) vector
  106. old_13h dw      2 dup(?)
  107.  
  108. vid_int     label    dword            ;int 10h (video) vector
  109. old_10h    dw    2 dup(?)
  110.  
  111. timer_int label dword                   ;int 1ch vector
  112. old_timer dw    2 dup(?)
  113.  
  114. key_int label   dword                   ;int 9h vector
  115. old_key dw      2 dup(?)
  116.  
  117. back_int label  dword                   ;int 28h vector
  118. old_28h dw      2 dup(?)
  119.  
  120. clear_int label dword                   ;clear out tsr interrupt
  121. old_clr dw      2 dup(?)
  122.  
  123. ;------------------------------------------------
  124. ; INTERRUPT HANDLERS
  125. ;------------------------------------------------
  126.  
  127. ;------------------------------------------------
  128. ; stime - every timer tick (1/18sec) comes here
  129. ;------------------------------------------------
  130.  
  131. stime   proc    far
  132.         sti
  133.  
  134.     pushf
  135.     call     timer_int         ;pass on vector for others first
  136.  
  137.         cmp     timed, -1            ;Is time triggering enabled?
  138.         jne     time1                ;no then don't do rest of this block
  139.         cmp     doswap, 1            ;want to swap?
  140.         je      time1                ;yes then skip next section
  141.         dec     period               ;count down
  142.         cmp     period, 0            ;is it zero yet?
  143.         jg      time1                ;if no then skip next
  144.         mov     doswap, 1            ;if yes then set doswap on
  145.  
  146. time1:
  147.  
  148.         cmp     swptog, 1            ;is swapping disabled?
  149.         jne     time2                ;no? then continue
  150.         jmp     far ptr time9        ;else exit
  151.  
  152. time2:
  153.  
  154.         cmp     doswap, 1            ;is doswap on
  155.         je      time3                ;yes jump into next check
  156.         jmp     far ptr time9        ;else exit
  157.  
  158. time3:
  159.  
  160.         cmp     inproc, 0            ;are we already engaged?
  161.         je      time4                ;no then proceed to next check
  162.         jmp     far ptr time9        ;else jump out
  163.  
  164. time4:
  165.  
  166.         mov     inproc, 1            ;signal we are engaged
  167.         cmp     hard_bz, 0           ;bios service in progress?
  168.         je      time5                ;no then proceed to next check
  169.         jmp     far ptr time8        ;else exit
  170.  
  171. time5:
  172.  
  173.         cmp     prob28h, 0           ;int 28 a problem? (0 = yes)
  174.         je      time6                ;yes, goto check dos busy
  175.         cmp     flag_28, 0           ;else, is int 28 in progress?
  176.         je      time6                ;no, check for dos busy
  177.         cmp     by28, 1              ;are we currently active on a 28 int?
  178.         je      time7                ;good! we can interrupt without
  179.                                      ;checking dos busy if TSR written
  180.                                      ;to not use dos below 0ch
  181. time6:
  182.  
  183.         push    es                   ;save ES and DI
  184.         push    di
  185.         mov     es,indoss            ;get DOS segment in ES
  186.         mov     di,indoso            ;address of DOS BUSY_FLAG in DI
  187.         cmp     byte ptr es:[di],0   ;DOS service currently active?
  188.         pop     di                   ;clean up
  189.         pop     es
  190.  
  191.         je      time7                ;not busy enter SWAP routine
  192.         jmp     far ptr time8        ;else, exit
  193.  
  194. time7:
  195.  
  196.     jmp    far ptr swpprc
  197.  
  198. time8:
  199.  
  200.         mov     inproc, 0            ;no longer in process
  201.  
  202. time9:
  203.  
  204.     cmp    by28, 0
  205.     je    time10
  206.     int    28h
  207.  
  208. time10:
  209.  
  210.         iret
  211.  
  212. stime   endp
  213.  
  214. ;-----------------------------------------------------------------
  215. ; bakprc - interrupt 28 spooler interrupt almost as good as timer
  216. ;-----------------------------------------------------------------
  217.  
  218. bakprc  proc    far
  219.         sti
  220.  
  221.     pushf
  222.     call    back_int         ;pass it on for others first
  223.  
  224.         mov     flag_28, 1           ;signal that int 28 in progress
  225.         cmp     prob28h, 0           ;Will we be using dos funcs below 0ch?
  226.         jne     bak1                 ;no? good, jump to next check
  227.         mov     flag_28, 0           ;otherwise no go, have to deny
  228.         iret                         ;return to calling process
  229.  
  230. bak1:
  231.  
  232.